//
//  YxrPicker.swift
//  TLCLockDemo
//
//  Created by run on 2024/7/24.
//

import SwiftUI

struct ContentValue<Content>: Identifiable {
    let value: Content
    let id: UUID = .init()
}

struct YxrPicker<SelectionValue>: View where SelectionValue: Hashable {
    let title: String
    let options: [(String, SelectionValue)]

    @Binding var selectValue: SelectionValue

    init(title: String, selectValue: Binding<SelectionValue>, options: [(String, SelectionValue)]) {
        self.title = title
        _selectValue = selectValue
        self.options = options
    }

    var body: some View {
        HStack {
            Text(title)
                .font(.body)
                .foregroundColor(.secondary)
                .frame(minWidth: 80, alignment: .leading)
            Spacer()
            Picker(selection: $selectValue) {
                ForEach(options, id: \.1) { value in
                    Text(value.0).tag(value.1)
                }
            } label: {
                Text(title)
            }
        }
        .padding(.horizontal, 20.0)
        .padding(.vertical, 3)
    }
}
